package com.yy.market.mvp.ui;

import android.os.Bundle;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.yy.market.R;

public class MainActivity extends BaseActivity {
    private FragmentTabHost mTabHost;
    private Class fragmentArray[] = {
            HomeFragment.class,
            CategoryFragment.class,
            CartFragment.class,
            UserFragment.class
    };
    private int iconArray[] = {
            R.drawable.main_tab_icon_home,
            R.drawable.main_tab_icon_category,
            R.drawable.main_tab_icon_cart,
            R.drawable.main_tab_icon_user,
    };
    private String titleArray[] = {"首页","品类","购物车","我的"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initPresenter() {

    }

    @Override
    protected void loadData() {

    }

    @Override
    protected void initView() {
        mTabHost = (FragmentTabHost) this.findViewById(R.id.tabhost);
        setupTabView();
    }

    private void setupTabView() {
        mTabHost.setup(this.getApplicationContext(), getSupportFragmentManager(), R.id
                .realtabcontent);
        mTabHost.getTabWidget().setDividerDrawable(null);

        int count = fragmentArray.length;
        for (int i = 0; i < count; i++) {
            TabHost.TabSpec tabSpec = mTabHost.newTabSpec(titleArray[i]).setIndicator
                    (getTabItemView(i));
            mTabHost.addTab(tabSpec, fragmentArray[i], null);
            mTabHost.getTabWidget().getChildAt(i);
        }

    }

    private View getTabItemView(int index) {
        LayoutInflater layoutInflater = LayoutInflater.from(this);
        View view = layoutInflater.inflate(R.layout.tab_bottom_nav, null);

        ImageView imageView = (ImageView) view.findViewById(R.id.iv_icon);
        imageView.setImageResource(iconArray[index]);

        TextView textView = (TextView) view.findViewById(R.id.tv_icon);
        textView.setText(titleArray[index]);
        return view;
    }

}
